<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./jq-3.6.0.js"></script>
    <style>
        .box {
            height: 100px;
            width: 100px;
            background-color: red;
        }
        
        .cadetblue {
            background-color: cadetblue;
        }
    </style>
</head>

<body>
    <button class="bn1">点击一下</button>
    <div class="box"></div>
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>
</body>
<script>
    // $(".bn1").click(function() {
    //     alert('33333')
    // });
    // $('.bn1').get(0).onclick = function() {
    // }
    //优势1. on能够绑定多个事件 处理不同逻辑
    $('.bn1').on({
        mouseover: function() {
            console.log('----mouseover-----');
        },
        mouseout: function() {
            console.log('----mouseout-----');
        },
        click: function() {
            console.log(111111111);
        }
    });
    //优势2. on能够绑定多个事件 处理相同逻辑
    $('.box').on('mouseover mouseout', function() {
        $(this).toggleClass("cadetblue");
    });
    //.click没办法动态给你帮点击事件
    // $('li').click(function() {
    //     alert("lilili")
    // });
    //优势3. 可通过事件委派来动态绑定点击事件
    $('ul').on('click', 'li', function() {
        alert('小琴最美辣');
    });
    var li4 = $('<li>4</li>');
    $('ul').append(li4);
</script>

</html>